package cn.htsyb.synergy.security.bean.param;

import cn.htsyb.synergy.orm.jpa.criterion.ExpressBuilder;
import cn.htsyb.synergy.orm.jpa.criterion.QueryExpress;
import cn.htsyb.synergy.orm.jpa.model.param.AbsStandardParam;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Type;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.List;
/**
 * 用户 参数类
 * codeMaker at 2020-07-14
 * @author lakeside hubin_yuan.410@hotmail.com
 * @since 2020-07-14
 */
@Setter
@Getter
@Schema(description = "用户参数")
public class SecurityUserParam extends AbsStandardParam {
    /**头像*/
    @Schema(name = "avatarUrl", description = "头像 ")
    protected  String avatarUrl;
    /**身份证号*/
    @Schema(name = "cardId", description = "身份证号 ")
    protected  String cardId;
    /**邮箱*/
    @Schema(name = "email", description = "邮箱 ")
    protected  String email;
    /**失效时间*/
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss", iso = DateTimeFormat.ISO.DATE_TIME)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Schema(name = "expiredTime", description = "失效时间 时间周期查询，数组查询方式:[start,end)，只有一个值时使用EQ，格式:yyyy-MM-dd HH:mm:ss")
    protected  Date[] expiredTime;
    /**是否内部配置*/

    @Schema(name = "hasInside", description = "是否内部配置 ")
    protected  Boolean hasInside;
    /**员工工号*/
    @Schema(name = "jobCode", description = "员工工号 ")
    protected  String jobCode;
    /**员工职位*/
    @Schema(name = "jobPost", description = "员工职位 ")
    protected  String jobPost;
    /**领导者*/
    @Schema(name = "leaderId", description = "领导者 ")
    protected  String leaderId;
    /**手机号*/
    @Schema(name = "mobile", description = "手机号 ")
    protected  String mobile;
    /**归属组织编码*/
    @Schema(name = "organizeCode", description = "归属组织编码 ")
    protected  String organizeCode;
    /**归属组织主键*/
    @Schema(name = "organizeId", description = "归属组织主键 ")
    protected  String organizeId;
    /**密码*/
    @Schema(name = "password", description = "密码 ")
    protected  String password;
    /**真实姓名*/
    @Schema(name = "realName", description = "真实姓名 ")
    protected  String realName;
    /**用户名*/
    @Schema(name = "username", description = "用户名 ")
    protected  String username;

    /**通用过滤*/
    @Schema(name = "filter", description = "通用过滤")
    protected String filter;

    @Override
    public List<QueryExpress> searchCriterion() {
        return ExpressBuilder.instance(super.searchCriterion())
                    .addExpressOfOperator(!StringUtils.isEmpty(avatarUrl), "avatarUrl", QueryExpress.Operator.EQ, avatarUrl)
                    .addExpressOfOperator(!StringUtils.isEmpty(cardId), "cardId", QueryExpress.Operator.EQ, cardId)
                    .addExpressOfOperator(!StringUtils.isEmpty(email), "email", QueryExpress.Operator.EQ, email)
                    .addExpressOfOperator(!ObjectUtils.isEmpty(expiredTime), "expiredTime", QueryExpress.Operator.EQ, expiredTime)
                    .addExpressOfOperator(!ObjectUtils.isEmpty(hasInside), "hasInside", QueryExpress.Operator.EQ, hasInside)
                    .addExpressOfOperator(!StringUtils.isEmpty(jobCode), "jobCode", QueryExpress.Operator.EQ, jobCode)
                    .addExpressOfOperator(!StringUtils.isEmpty(jobPost), "jobPost", QueryExpress.Operator.EQ, jobPost)
                    .addExpressOfOperator(!StringUtils.isEmpty(leaderId), "leaderId", QueryExpress.Operator.EQ, leaderId)
                    .addExpressOfOperator(!StringUtils.isEmpty(mobile), "mobile", QueryExpress.Operator.EQ, mobile)
                    .addExpressOfOperator(!StringUtils.isEmpty(organizeCode), "organizeCode", QueryExpress.Operator.EQ, organizeCode)
                    .addExpressOfOperator(!StringUtils.isEmpty(organizeId), "organizeId", QueryExpress.Operator.EQ, organizeId)
                    .addExpressOfOperator(!StringUtils.isEmpty(password), "password", QueryExpress.Operator.EQ, password)
                    .addExpressOfOperator(!StringUtils.isEmpty(realName), "realName", QueryExpress.Operator.EQ, realName)
                    .addExpressOfOperator(!StringUtils.isEmpty(username), "username", QueryExpress.Operator.EQ, username)
                .build();
    }

    @Override
    public List<QueryExpress> filterCriterion() {
        boolean bool=!StringUtils.isEmpty(filter);

        return ExpressBuilder.instance(super.filterCriterion())
                /*需要自行根据索引调整可支持的通用查询字段，切不可全字段通用查询
                .addExpressOfOperator(bool,"avatarUrl",QueryExpress.Operator.LIKE, filter)
                .addExpressOfOperator(bool,"cardId",QueryExpress.Operator.LIKE, filter)
                .addExpressOfOperator(bool,"email",QueryExpress.Operator.LIKE, filter)
                .addExpressOfOperator(bool,"jobCode",QueryExpress.Operator.LIKE, filter)
                .addExpressOfOperator(bool,"jobPost",QueryExpress.Operator.LIKE, filter)
                .addExpressOfOperator(bool,"leaderId",QueryExpress.Operator.LIKE, filter)
                .addExpressOfOperator(bool,"mobile",QueryExpress.Operator.LIKE, filter)
                .addExpressOfOperator(bool,"organizeCode",QueryExpress.Operator.LIKE, filter)
                .addExpressOfOperator(bool,"organizeId",QueryExpress.Operator.LIKE, filter)
                .addExpressOfOperator(bool,"password",QueryExpress.Operator.LIKE, filter)
                .addExpressOfOperator(bool,"realName",QueryExpress.Operator.LIKE, filter)
                .addExpressOfOperator(bool,"username",QueryExpress.Operator.LIKE, filter)
                 */
                .build();
    }
}